package com.kexuexiong.demo.bear.common.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    /**
     * 参数错误
     */
    public static final String E1000="E1000";

    /**
     * 系统错误
     */
    public static final String E1001 = "E1001";

    private Boolean success = false;

    @ApiModelProperty(name = "code",notes = "业务code")
    private String code;

    @ApiModelProperty(name = "msg",notes = "返回消息")
    private String msg;

    @ApiModelProperty(name = "data",notes = "反会数据")
    private T data;

    public static Result success() {
        return new Result(true, "ok", "成功", null);
    }

    public Result setSuccessResult(){
        this.setSuccess(true);
        return this;
    }

    public static <T> Result fail(T data) {
        return new Result(false, "fail", "失败", data);
    }

    public static <T> Result fail(T data, String code) {
        return new Result(false, code, "失败", data);
    }

    public static <T> Result fail(T data, String code, String msg) {
        return new Result(false, code, msg, data);
    }

    public static <T> Result success(T data) {
        return new Result(true, "ok", "成功", data);
    }
}
